Macromedia Flash Article

Bike Trips Sample Application: Using the XMLConnector Component in Flash MX Professional 2004


Table of Contents

  1. Introduction
  2. Getting Started: Examining the Bike Trips Application and Its Data
  3. Configuring the Application to Use the XMLConnector Component
  4. Binding XML Data to a ComboBox Component
  5. Creating ComboBox Labels Using XML Data
  6. Displaying and Updating a Trip Description in a TextArea Component
  7. Displaying and Updating a Formatted Cost in a TextInput Component
  8. Displaying and Updating a Graphic in a Loader Component
  9. Summary and Related Articles and Resources

Binding XML Data to a ComboBox Component

  1. Save XMLConnector_step1.fla as XMLConnector_step2.fla.
  2. Open the Components panel, drag an instance of the ComboBox component onto the Stage, and drop it below the word "Trip."
  3. Open the Property inspector for this new ComboBox instance and set the following values:

    • Instance name: cbTrips
    • Width: 120

    Note: While you can set static, default labels and data in the Property inspector, do not do so here as the XMLConnector component will dynamically provide the labels and data for this ComboBox.

  4. Expose the array of trip objects from the xcTrips XMLConnector as an available binding:

    1. Select xcTrips.
    2. Open the Component Inspector panel and select the Bindings tab.
    3. Click the Plus (+) button to add a new data binding, exposing the imported XML data schema, which you previously bound to xcTrips.
    4. Select the array of trip objects (called trip:Array) from the schema and press OK.
    5. You should now see that the results.trips.trip property of xcTrips listed as a binding attached to xcTrips.
  5. Attach the newly exposed binding to the dataProvider property of the cbTrips ComboBox:

    1. Select the results.trips.trip binding from the Bindings tab in the Component Inspector panel for the xcTrips XMLConnector.
    2. In the Bindings property grid, below the binding, set the direction property for this binding to out.
    3. Select the bound to property and press the magnifying glass tool button.
    4. In the Bound To dialogue, set the following:

      • Component path: ComboBox <cbTrips>
      • Schema location: dataProvider : Array

    Data bindings are data connections between components that Flash maintains automatically. A binding may be one-directional or two-directional. In this case, you've created a one-directional binding going "out" from the trip:Array in xcTrips (xcTrips:results.trips.trip) and "in" to the cbTrips ComboBox. Because a ComboBox can only display one String as a label for each row, you must to specify which values from the trip:Array should be the labels for the cbTrips ComboBox.